home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / imdialogs.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  6KB  |  141 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from gui.uberwidgets.UberCombo import UberCombo
  6. from gui.uberwidgets.simplemenu import SimpleMenuItem
  7. from gui.imwin import begin_conversation
  8. from gui.toolbox import persist_window_pos
  9. from gui.validators import LengthLimit
  10. from wx import EXPAND, ALL, VERTICAL, HORIZONTAL, ALIGN_CENTER_VERTICAL, ALIGN_RIGHT, DEFAULT_DIALOG_STYLE, FRAME_FLOAT_ON_PARENT
  11. from common import profile, pref
  12. from util import oset
  13.  
  14. def ShowNewIMDialog():
  15.     NewIMDialog.MakeOrShow()
  16.  
  17.  
  18. class NewIMDialog(wx.Dialog):
  19.     
  20.     def __init__(self):
  21.         wx.Dialog.__init__(self, None, -1, _('New IM'), style = DEFAULT_DIALOG_STYLE | FRAME_FLOAT_ON_PARENT)
  22.         self.Name = 'New IM Dialog'
  23.         self.Sizer = wx.BoxSizer(VERTICAL)
  24.         p = wx.Panel(self, -1)
  25.         self.Sizer.Add(p, 1, EXPAND)
  26.         p.Sizer = wx.BoxSizer(VERTICAL)
  27.         s = wx.FlexGridSizer(2, 2)
  28.         s.AddGrowableCol(1, 1)
  29.         p.Sizer.Add(s, 1, EXPAND)
  30.         toctrl = self.toctrl = wx.TextCtrl(p, style = wx.TE_PROCESS_ENTER, validator = LengthLimit(255))
  31.         toctrl.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
  32.         fromcombo = self.fromcombo = UberCombo(p, None, skinkey = 'AppDefaults.PrefCombo')
  33.         fromcombo.SetItems(self.UpdateAccountItems(), 0)
  34.         
  35.         Text = lambda t: wx.StaticText(p, -1, t)
  36.         s.Add(Text(_('To')), 0, ALIGN_RIGHT | ALIGN_CENTER_VERTICAL | ALL, 3)
  37.         s.Add(toctrl, 1, EXPAND | ALIGN_CENTER_VERTICAL | ALL, 3)
  38.         s.Add(Text(_('From')), 0, ALIGN_RIGHT | ALIGN_CENTER_VERTICAL | ALL, 3)
  39.         s.Add(fromcombo, 1, EXPAND | ALIGN_CENTER_VERTICAL | ALL, 3)
  40.         bs = wx.BoxSizer(HORIZONTAL)
  41.         sendbutton.Enable(False)
  42.         sendbutton.Bind(wx.EVT_BUTTON, self.OnAccept)
  43.         cancelbutton.Bind((wx.EVT_BUTTON,), (lambda e: self.Close()))
  44.         bs.Add(sendbutton, 0, ALL, 3)
  45.         bs.Add(cancelbutton, 0, ALL, 3)
  46.         p.Sizer.Add(bs, 0, ALIGN_RIGHT | ALL, 3)
  47.         self.Fit()
  48.         self.Size = wx.Size(300, self.Size.height)
  49.         profile.account_manager.connected_accounts.add_observer(self.WhenOnlineAcctsChange)
  50.         Bind = self.Bind
  51.         Bind(wx.EVT_CLOSE, self.OnClose)
  52.         Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
  53.         persist_window_pos(self, defaultrect = 'center')
  54.  
  55.     
  56.     def WhenOnlineAcctsChange(self, *a):
  57.         fromcombo = self.fromcombo
  58.         fromcombo.SetItems(self.UpdateAccountItems())
  59.         if fromcombo.Value not in fromcombo:
  60.             if len(fromcombo):
  61.                 fromcombo.SetSelection(0)
  62.             else:
  63.                 fromcombo.Value = _('No Connections')
  64.         
  65.         self.UpdateButtonState()
  66.  
  67.     
  68.     def UpdateAccountItems(self):
  69.         if not hasattr(self, 'acctitems'):
  70.             self.acctitems = oset()
  71.         
  72.         acctitems = self.acctitems
  73.         accounts = oset(profile.account_manager.connected_accounts)
  74.         accts = set((lambda .0: for item in .0:
  75. item.id)(acctitems))
  76.         newaccts = accounts - accts
  77.         oldaccts = accts - accounts
  78.         for item in set(acctitems):
  79.             if item.id in oldaccts:
  80.                 acctitems.remove(item)
  81.                 continue
  82.         
  83.         for account in newaccts:
  84.             if account.allow_contact_add:
  85.                 acctitems.add(SimpleMenuItem([
  86.                     account.serviceicon.Resized(16),
  87.                     account.username], id = account))
  88.                 continue
  89.         
  90.         return list(acctitems)
  91.  
  92.     
  93.     def OnKeyDown(self, event):
  94.         ctrl = event.ControlDown()
  95.         key = event.GetKeyCode()
  96.         if ctrl and key == wx.WXK_DOWN:
  97.             self.fromcombo.SelectNextItem(True)
  98.         elif ctrl and key == wx.WXK_UP:
  99.             self.fromcombo.SelectPrevItem(True)
  100.         elif key == wx.WXK_ESCAPE:
  101.             self.Close()
  102.         elif key == wx.WXK_RETURN and bool(self.toctrl.Value) and len(self.fromcombo):
  103.             self.OnAccept()
  104.         else:
  105.             event.Skip()
  106.         self.UpdateButtonState()
  107.  
  108.     
  109.     def UpdateButtonState(self):
  110.         (wx.CallAfter,)((lambda : if bool(self.toctrl.Value):
  111. passself.sendbutton.Enable(len(self.fromcombo))))
  112.  
  113.     
  114.     def OnAccept(self, event = None):
  115.         self.Hide()
  116.         proto = self.fromcombo.Value.id.connection
  117.         begin_conversation(proto.get_buddy(self.toctrl.Value))
  118.         self.Close()
  119.  
  120.     
  121.     def OnClose(self, event):
  122.         profile.account_manager.connected_accounts.remove_observer(self.WhenOnlineAcctsChange)
  123.         self.Show(False)
  124.         type(self).new_im_instance = None
  125.         self.Destroy()
  126.  
  127.     
  128.     def MakeOrShow(cls):
  129.         if not hasattr(cls, 'new_im_instance'):
  130.             cls.new_im_instance = None
  131.         
  132.         if cls.new_im_instance:
  133.             cls.new_im_instance.Show(True)
  134.             cls.new_im_instance.Raise()
  135.         else:
  136.             cls.new_im_instance = NewIMDialog()
  137.             cls.new_im_instance.Show(True)
  138.  
  139.     MakeOrShow = classmethod(MakeOrShow)
  140.  
  141.